package com.smartcruise.base;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.util.Log;

import com.smartcruise.util.IntentUtils;

/**
 * Created by FengChaoQun
 * on 2018/1/21 0021
 * 只有一个fragment的activity的简单实现类 根据传来的class信息展示fragment
 */

public class FragmentActivitySimpleImp extends BaseFragmentActivity {

    public static void start(Context context, Class<? extends Fragment> cl) {
        Intent intent = new Intent(context, FragmentActivitySimpleImp.class);
        intent.putExtra(IntentUtils.TYPE, cl);
        context.startActivity(intent);
    }

    @Override
    protected Fragment getFragment() {
        Class cl = (Class) getIntent().getSerializableExtra(IntentUtils.TYPE);
        if (cl != null) {
            if (Fragment.class.isAssignableFrom(cl)) {
                try {
                    return (Fragment) cl.newInstance();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            } else {
                Log.d("BaseFragmentActivityImp", "class is not fragment");
            }
        } else {
            Log.d("BaseFragmentActivityImp", "class is null");
        }
        return null;
    }

}
